<#assign uncapClassName = className?uncap_first>
package com.yangye.${moduleName}.controller;

import com.yangye.picommon.model.PiResult;
import com.yangye.picommon.model.page.PageRequest;
import com.yangye.picommon.model.page.PageResult;
import com.yangye.${moduleName}.domain.${className};
import com.yangye.${moduleName}.service.${className}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
* @author yangye
* @date ${.now?date}
* 自动生成代码
*/
@RestController
@RequestMapping("${apiPath}")
public class ${className}Controller {

    @Autowired
    private ${className}Service ${uncapClassName}Service;

    /**
    * 新增
    * @param ${uncapClassName}
    * @return
    */
    @PostMapping("/")
    @PreAuthorize("hasAuthority('${authPrefix}:add')")
    PiResult add(@RequestBody ${className} ${uncapClassName}) {
        ${uncapClassName}Service.add(${uncapClassName});
        return PiResult.succeed();
    }

    /**
    * 删除
    * @param id
    * @return
    */
    @DeleteMapping("/{id}")
    @PreAuthorize("hasAuthority('${authPrefix}:remove')")
    PiResult remove(@PathVariable Long id) {
        ${uncapClassName}Service.remove(id);
        return PiResult.succeed();
    }

    /**
    * 修改
    * @param ${uncapClassName}
    * @return
    */
    @PutMapping("/")
    @PreAuthorize("hasAuthority('${authPrefix}:update')")
    PiResult update(@RequestBody ${className} ${uncapClassName}) {
        ${uncapClassName}Service.update(${uncapClassName});
        return PiResult.succeed();
    }

    /**
    * 查看详情
    * @param id
    * @return
    */
    @GetMapping("/{id}")
    @PreAuthorize("hasAuthority('${authPrefix}:view')")
    PiResult get(@PathVariable Long id) {
        ${className} ${uncapClassName} = ${uncapClassName}Service.get(id);
        return PiResult.succeed(${uncapClassName});
    }

    /**
    * 查看分页
    * @param ${uncapClassName}
    * @param pageRequest
    * @return
    */
    @GetMapping("/page")
    @PreAuthorize("hasAuthority('${authPrefix}')")
    PiResult listPage(${className} ${uncapClassName}, PageRequest pageRequest) {
    PageResult<${className}> page = ${uncapClassName}Service.findPage(${uncapClassName}, pageRequest);
        return PiResult.succeed(page);
    }
}